import request from "@/utils/request";

// 查询优惠券列表
export function listCoupon(query) {
  return request({
    url: "/business/coupon/list",
    method: "get",
    params: query,
  });
}

// 查询优惠券详细
export function getCoupon(id) {
  return request({
    url: "/business/coupon/" + id,
    method: "get",
  });
}

// 新增优惠券
export function addCoupon(data) {
  return request({
    url: "/business/coupon",
    method: "post",
    data: data,
  });
}

// 修改优惠券
export function updateCoupon(data) {
  return request({
    url: "/business/coupon",
    method: "put",
    data: data,
  });
}

// 删除优惠券
export function delCoupon(ids) {
  return request({
    url: "/business/coupon/" + ids,
    method: "delete",
  });
}

// 修改优惠券状态
export function changeStatus(id, status,couponNum,everyoneCoupon) {
  const data = {
    id,
    isEnable: status,
    couponNum:couponNum,
    everyoneCoupon:everyoneCoupon
  };
  return request({
    url: "/business/coupon",
    method: "put",
    data: data,
  });
}

// 修改优惠券显隐性
export function changeDisplay(id, display) {
  const data = {
    id,
    isDisplay: display,
  };
  return request({
    url: "/business/coupon",
    method: "put",
    data: data,
  });
}

// 赠送优惠券
export function sendCoupon(couponIds, customerIds) {
  return request({
    url: "/business/coupon/send",
    method: "get",
    params: {
      // 使用params传递数组参数
      couponIds: couponIds.join(","),
      customerIds: customerIds.join(","),
    },
  });
}

// 获取优惠券背景模板列表
export function listCouponTemplates(source) {
  return request({
    url: "/business/coupon/listCouponTemplates",
    method: "get",
    params: { source },
  });
}

// 修改失效状态
export function changeExpiredStatus(data) {
  return request({
    url: "/business/coupon/changeExpiredStatus",
    method: "post",
    data: data,
  });
}
